<?php

$str_chart_source = $this->str_chart_source;

// don't render anything if there isn't an image source
if(!empty($str_chart_source)) {

    $arr_echo = array();

    $str_caption = isset($this->arr_meta['caption']) && !empty($this->arr_meta['caption'])
        ? $this->arr_meta['caption']
        : null;
    $str_source = isset($this->arr_meta['source']) && !empty($this->arr_meta['source'])
        ? $this->arr_meta['source']
        : null;
    $arr_notes = isset($this->arr_meta['notes']) && !empty($this->arr_meta['notes'])
        ? (array) $this->arr_meta['notes']
        : null;

    $bln_include_caption = true;
    if(isset($this->embed_caption)) {          
        $bln_include_caption = false;
    }
        
    $str_tag = (isset($this->use_div_structure) && ($this->use_div_structure == true)) ? 'div' : 'span';

    $arr_echo[] = '<' . $str_tag . ' class="chart">';

    if(!empty($str_caption) && $bln_include_caption) {
        $arr_echo[] = '<' . $str_tag . ' class="caption">' . $str_caption . '</' . $str_tag . '>';
    }

    $arr_echo[] = '<img src="' . $str_chart_source . '" alt="Chart" title="Chart"/>';

    if(!empty($str_source)) {
        $arr_echo[] = '<' . $str_tag . ' class="source">' . $str_source . '</' . $str_tag . '>';
    }
    
    if(isset($this->int_sampling_size) && ($this->int_sampling_size > 1)) {
        $str_note = 'Note: Due to the large quantity of data selected, the chart displays an average of every ' . $this->int_sampling_size . ' points.';
        $arr_notes[] = $str_note;
    }
    
    
    if(!empty($arr_notes)) {
        foreach($arr_notes as $str_note) {
            if(!empty($str_note)) {
                $arr_echo[] = '<' . $str_tag . ' class="note">' . $str_note . '</' . $str_tag . '>';
            }
        }
    }

    $arr_echo[] = '</' . $str_tag . '>';

    echo implode('', $arr_echo);
    
}
